package com.scorpio.baselibrary.utils.glide;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.signature.ObjectKey;

import java.io.InputStream;

/**
 * created by zhud on 2019/9/29
 */
public class ApkIconModelLoader implements ModelLoader<PackageInfo, InputStream> {
    private Context context;

    public ApkIconModelLoader(Context context) {
        this.context = context;

    }

    @Nullable
    @Override
    public LoadData<InputStream> buildLoadData(@NonNull PackageInfo packageInfo, int width, int height, @NonNull Options options) {
        return new LoadData<>(new ObjectKey(packageInfo), new ApkIconFetcher(context, packageInfo));
    }

    @Override
    public boolean handles(@NonNull PackageInfo packageInfo) {
        return true;
    }
}